<html>
<head><meta charset="utf-8"><title>Identify a well-known trait via TraitRef · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Identify.20a.20well-known.20trait.20via.20TraitRef.html">Identify a well-known trait via TraitRef</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="217324743"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Identify%20a%20well-known%20trait%20via%20TraitRef/near/217324743" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Identify.20a.20well-known.20trait.20via.20TraitRef.html#217324743">(Nov 19 2020 at 20:16)</a>:</h4>
<p>Is is possible to easily compare/identify a <code>rustc_middle::TraitRef</code>? I want to skip <code>core::marker::Structural(Partial)Eq</code> and am currently doing it via pretty-printing with <code>def_path_str</code> (<code>def_path_str(def_id).contains("::marker::Structural")</code> <span aria-label="rolling eyes" class="emoji emoji-1f644" role="img" title="rolling eyes">:rolling_eyes:</span> )</p>
<p>It seems wasteful to print every trait candidate to only potentially skip these few. Is it possible to, let's say, get a def to <code>core::marker::StructuralEq</code> myself?</p>



<a name="217326148"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Identify%20a%20well-known%20trait%20via%20TraitRef/near/217326148" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Igor Matuszewski <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Identify.20a.20well-known.20trait.20via.20TraitRef.html#217326148">(Nov 19 2020 at 20:29)</a>:</h4>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">structural_teq_def_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">require_lang_item</span><span class="p">(</span><span class="n">LangItem</span>::<span class="n">StructuralTeq</span><span class="p">,</span><span class="w"> </span><span class="nb">None</span><span class="p">);</span><span class="w"></span>
<span class="w">    </span><span class="kd">let</span><span class="w"> </span><span class="n">structural_peq_def_id</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">tcx</span><span class="p">.</span><span class="n">require_lang_item</span><span class="p">(</span><span class="n">LangItem</span>::<span class="n">StructuralPeq</span><span class="p">,</span><span class="w"> </span><span class="nb">None</span><span class="p">);</span><span class="w"></span>
</code></pre></div>
<p>seems to work =)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>